﻿Public Class CINOACLabelState2 : Inherits CStateBase

    ''' <summary>
    ''' 実行可能かを判断する
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function IsEnter(ByVal task As CTaskBase) As Boolean
        Debug.WriteLine("CINOACLabelState2.IsEnter")
        If CCommon.isInStr(task.ActionCd, "LABEL-I") Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 実行メソッド
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function DoExecute(ByVal task As CTaskBase) As CStateBase
        Dim nextState As CStateBase
        Dim pdaTask As CPDATask2 = DirectCast(task, CPDATask2)
        Debug.WriteLine("CINOACLabelState2.DoExecute")
        Dim readText As String = task.ProcessText
        Dim itemCd As String = CCommon.TrimCode(readText, CCommon.EnumGetString.LBL_I_ITEM_CD)
        Dim uniqueCd As String = CCommon.TrimCode(readText, CCommon.EnumGetString.LBL_I_UNIQUE_CD)

        ''読込み済みのラベルではないか確認（ユニークコード）N:アラート
        Dim uniqueCdInfo As CPDATask2.strctUniqueCdInfo = Nothing
        uniqueCdInfo.labelType = CCommon.LABEL_INOAC
        uniqueCdInfo.itemCd = itemCd
        uniqueCdInfo.uniqueCd = uniqueCd
        uniqueCdInfo.readDateTime = Now()

        Select Case pdaTask.addUniqueCd(uniqueCdInfo)
            Case -1
                ''アラート
                Dim result As String = ""
                Dim prevWindowMode As EnumWindowMode
                Do While result <> "[OK]"
                    If result = "" Then
                        pdaTask.Hardware.alert()
                        prevWindowMode = pdaTask.WindowManager.GetWindowMode()
                        pdaTask.WindowManager.SetAlertMessage(CCommon.CNS_MSG_015, CCommon.COLOR_BLACK, CCommon.COLOR_WHITE)
                        pdaTask.WindowManager.ChangeWindowMode(EnumWindowMode.ALERT_MODE)
                        'Debug.WriteLine(CCommon.CNS_MSG_015)

                    End If
                    result = task.ReadTextWait(-1)
                    'Debug.WriteLine("RESULT:{0},{1}", result, task.ProcessText)
                Loop
                pdaTask.WindowManager.ChangeWindowMode(prevWindowMode)
            Case 2
                ''マツダ重複
            Case 1
                ''区切りラベル
                ''（社内ラベルが存在しているかのチェック）
                If pdaTask.isInChildLabel() Then
                    ''前回のシングル構造体をLabelInfoにセット
                    If pdaTask.addLabelInfo(itemCd, uniqueCd) Then
                        ''新規でシングル構造体を作成
                        pdaTask.clrSingleLabelInfo()
                    End If
                    pdaTask.addSingleLabelInfo(readText, "", itemCd, CCommon.LABEL_INOAC, 0, False)

                Else
                    ''エラー
                    pdaTask.Hardware.warning()
                    ''前回読込んだ親ラベルに対して子ラベルが読込まれていない
                    pdaTask.delLastUniqueCd() ''登録したユニークコードを削除


                    Dim result As String = ""
                    Dim prevWindowMode As EnumWindowMode
                    Do While result <> "[OK]"
                        If result = "" Then
                            prevWindowMode = pdaTask.WindowManager.GetWindowMode()
                            pdaTask.WindowManager.SetAlertMessage(CCommon.CNS_MSG_016, CCommon.COLOR_WHITE, CCommon.COLOR_RED)
                            pdaTask.WindowManager.ChangeWindowMode(EnumWindowMode.ALERT_MODE)
                        End If
                        result = task.ReadTextWait(-1)
                        'Debug.WriteLine("RESULT:{0},{1}", result, task.ProcessText)
                    Loop
                    pdaTask.WindowManager.ChangeWindowMode(prevWindowMode)




                    task.ErrorCd = "ER"
                    task.ProcessText = ""
                    nextState = GetNextState(task, GetType(CErrorState2))
                    Return nextState
                End If


        End Select

        task.ActionCd = "LABEL"
        task.ProcessText = ""
        nextState = GetNextState(task)
        Return nextState
    End Function

    ''' <summary>
    ''' 終了メソッド(未使用)
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function DoExit(ByVal task As CTaskBase) As Boolean
        Debug.WriteLine("CINOACLabelState2.DoExit")
        Return True
    End Function


End Class
